<?php
	class MetaInformationController extends AppController
	{
		var $name = "MetaInformation";
		
		function admin_setInfo($entity,$entityId = null)
		{
			$pageName = false;	
			if(!$entity && !$entityId)
			{
				die("NOT A VALID PAGE CLOSE THE POPUP");
			}else if(!$entityId)
			{
				$pageName = $entity;
				if(!isset($this->MetaInformation->pages[$pageName]))
				{
					die("NOT A VALID PAGE CLOSE THE POPUP");
				}
			}
			
				
			if($this->data)
				{
					if($pageName)
					{
						$this->data['MetaInformation']['page_name'] = $pageName;
						$id = $this->MetaInformation->field("id",array("page_name"=>$pageName));
					}else
					{
						$this->data['MetaInformation']['entity'] = $entity;
						$this->data['MetaInformation']['entity_id'] = $entityId;
						$id = $this->MetaInformation->field("id",array("entity"=>$entity,'entity_id'=>$entityId));
					}
					$this->MetaInformation->create();
					$this->MetaInformation->id = $id;
					if($this->MetaInformation->save($this->data))
					{
						$this->successMsg("Meta information has been saved.");
						$this->redirect($this->params['pass']);	
					}
				}else
				{
					if($pageName)
					{
						$metaInfo = $this->MetaInformation->getPageMetaInformation($pageName,true);
					}else
					{
						$metaInfo = $this->MetaInformation->getMetaInformation($entity,$entityId,true);
					}
					$this->data['MetaInformation'] = $metaInfo;
				}
		}

		function admin_pages()
		{
			$pages = $this->MetaInformation->pages;
			$this->set("pages",$pages);
		}
	}
?>